﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.actions {
    import Engine.Helpers.*;
    import Classes.*;
    import Engine.*;

    public class ActionTranslate extends NPCAction {

        protected var m_startPos:Vector3;
        protected var m_endPos:Vector3;
        protected var m_progress:Number;
        protected var m_duration:Number;

        public function ActionTranslate(_arg1:NPC, _arg2:Number, _arg3:Vector3, _arg4:Vector3=null){
            super(_arg1);
            this.m_startPos = _arg4;
            this.m_endPos = _arg3;
            this.m_duration = _arg2;
            this.m_progress = 0;
        }
        override public function enter():void{
            super.enter();
            this.resetTranslation();
        }
        override public function reenter():void{
            super.reenter();
            this.resetTranslation();
        }
        protected function resetTranslation():void{
            if (this.m_startPos == null){
                this.m_startPos = m_npc.getPosition();
            };
            this.m_progress = 0;
            var _local1:Vector3 = this.m_endPos.subtract(this.m_startPos);
            var _local2:int = this.getMovementDirection(_local1);
            if (_local2 != m_npc.getDirection()){
                m_npc.setDirection(_local2);
                m_npc.setState(m_npc.getState());
            };
        }
        override public function update(_arg1:Number):void{
            this.m_progress = (this.m_progress + _arg1);
            var _local2:Number = (this.m_progress / this.m_duration);
            if (_local2 >= 1){
                _local2 = 1;
                m_npc.getStateMachine().removeState(this);
            };
            var _local3:Vector3 = Vector3.lerp(this.m_startPos, this.m_endPos, _local2);
            m_npc.setPosition(_local3.x, _local3.y);
            m_npc.conditionallyReattach();
        }
        protected function getMovementDirection(_arg1:Vector3, _arg2:Number=0):int{
            if (Math.abs(_arg1.x) > Math.abs(_arg1.y)){
                if (_arg1.x > _arg2){
                    return (Constants.DIRECTION_NE);
                };
                if (_arg1.x < -(_arg2)){
                    return (Constants.DIRECTION_SW);
                };
            } else {
                if (_arg1.y > _arg2){
                    return (Constants.DIRECTION_NW);
                };
                if (_arg1.y < -(_arg2)){
                    return (Constants.DIRECTION_SE);
                };
            };
            return (Constants.DIRECTION_MAX);
        }
        override public function getInterrupt():int{
            return (NO_INTERRUPT);
        }

    }
}//package Classes.actions 
